unit ScienceFun;

interface

uses Math;

function MaxBoltzDistr(a:double; x:double): double;
function MaxBoltzDistrCDF(a:double; x:double): double;

implementation

function MaxBoltzDistr(a:double; x:double): double;
begin
 result:= sqrt(2/pi)*x*x*exp(-x*x/(2*a*a))/Power(a,3);
end;

function MaxBoltzDistrCDF(a:double; x:double): double;
var a1,a2,a3,a4: double;
erf, z: double;
begin
 a1 := 0.278393;
 a2 := 0.230389;
 a3 := 0.000972;
 a4 := 0.078108;
 z:=x/(sqrt(2)*a);

// aa:=(-8/(3*pi))*((pi - 3)/(pi - 4));
 erf:=1-1/Power(1+a1*z+a2*z*z+a3*z*z*z+a4*z*z*z*z, 4);
 result:=erf -sqrt(2/pi)*(x*exp(-x*x/(2*a*a)))/a;
end;

end.
